﻿namespace Authentication.Data.DBConfig
{
    using Authentication.Configuration;
    using Authentication.Model.Model;
    using Common.Data.Extensions;
    using System.Data.Entity.ModelConfiguration;

    public class AccountConfiguration : DBConfig<Account>
    {
        public AccountConfiguration()
            : base(SystemConfiguration.Schema, SystemConfiguration.NamingType, SystemConfiguration.TABLE_PREFIX)
        {
            HasKey(k => new { k.ApplicationKey, k.UserName });
            Property(c => c.ApplicationKey).HasMaxLength(36).IsRequired();
            Property(c => c.UserName).HasMaxLength(128).IsRequired();
            Property(c => c.Password).HasMaxLength(128).IsRequired();
            Property(c => c.Active).HasMaxLength(1).IsRequired();

            //relationship
            HasOptional(t => t.Group).WithMany(c => c.Accounts).HasForeignKey(t => new { t.ApplicationKey, t.GroupId }).WillCascadeOnDelete(false);
        }
    }
}
